import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
    {
        path: '*',
        redirect: '/index'
    },
    {
        name: 'index',
        component: () => import('./view/index'),
        meta: {
            title: '保险帮'
        }
    },
    {
        name: 'list',
        component: () => import('./view/list'),
        meta: {
            title: '优秀业务员'
        }
    },
    {
        name: 'salesman',
        component: () => import('./view/salesman'),
        meta: {
            title: '名片'
        }
    },
    {
        name: 'register',
        component: () => import('./view/register'),
        meta: {
            title: '注册'
        }
    },
    {
        name: 'succ',
        component: () => import('./view/succ'),
        meta: {
            title: '恭喜，注册成功'
        }
    }
];

// add route path
routes.forEach(route => {
    route.path = route.path || '/' + (route.name || '');
});

const router = new Router({routes});

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = title;
    }
    next();
});

export {
    router
};
